﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;


namespace System
{
    public static class SystemExtensions
    {
        /// <summary>
        /// Extention of string to make a paskal or camel case string to a logical text. for example("ThisIsASample1Text => This Is A Sample 1 Text)
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string ToCaseWords(this string value)
        {
            Regex r = new Regex(@"(?<=[A-Z])(?=[A-Z][a-z])|(?<=[^A-Z])(?=[A-Z])|(?<=[A-Za-z])(?=[^A-Za-z])", RegexOptions.IgnorePatternWhitespace);
            return r.Replace(value, " ");
        }

        public static Byte[] ToByteArray(this string value, Encoding encoding)
        {
            Byte[] byteArray = encoding.GetBytes(value);
            return byteArray;
        }

        public static String ToString(this Byte[] value, Encoding encoding)
        {
            String constructedString = encoding.GetString(value, 0, value.Length);
            return (constructedString);
        }

        /// <summary>
        /// It removes all non ascii chars from string. We added especially for stripping StaticContent.Description 
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string RemoveNonAsciiChars(this string value)
        {
            return Regex.Replace(value, @"[^\x20-\x7F]", "");
        }

    }
}